package com.dingding.queue.base.push;

import java.util.Map;

import com.dingding.common.core.config.JPushConfig;
import com.dingding.facade.queue.enums.RoleType;

import cn.jpush.api.JPushClient;
import cn.jpush.api.push.model.PushPayload;

/**
 * 
 * @ClassName: AbstractSendPush 
 * @Description: 极光推送抽象类
 * @author CHEHAUNBO 
 * @date 2016年6月6日 下午10:52:22
 * 
 */
public abstract class AbstractSendPush {

	protected static JPushClient iosJPushClient = null;
	protected static JPushClient androidJPushClient = null;
	protected static JPushClient driverJpushClient = null;// 车主端推送

	public AbstractSendPush() {
		intitalJpushClient();
	}

	/**
	 * 
	 * 初始化推送客户端
	 * 
	 * @Title: intitalJpushClient     设定文件 
	 * @author CHEHAUNBO
	 * 
	 */
	public synchronized void intitalJpushClient() {

		if (iosJPushClient == null) {
			iosJPushClient = new JPushClient(JPushConfig.getIOS_MASTER_SECRET(), JPushConfig.getIOS_APP_KEY());
		}

		if (androidJPushClient == null) {
			androidJPushClient = new JPushClient(JPushConfig.getANDROID_MASTER_SECRET(),
					JPushConfig.getANDROID_APP_KEY());
		}

		if (driverJpushClient == null) {
			driverJpushClient = new JPushClient(JPushConfig.getDRIVER_MASTER_SECRET(), JPushConfig.getDRIVER_APP_KEY());
		}

	}

	/**
	 *
	 * 执行消息推送
	 * 
	 * @Title: excuteSendPush 
	 * @param pushPayload
	 * @author CHEHAUNBO
	 * 
	 */
	public abstract boolean excuteSendPush(PushPayload pushPayload, RoleType roleType);

	/**
	 * 
	 * 推送消息,包含(通知、标题、自定义内容、自定义参数)
	 * 
	 * @param aliasId 手机设备在极光绑定的设备别名
	 * @param alert 通知，显示在手机通知栏中的内容
	 * @param msgTitle 自定义标题
	 * @param msgContent 自定义消息的内容
	 * @param map 自定义参数的内容
	 * @param clientType 推送设备的类型(iOS/Android)
	 * @author cheshaowei
	 * 
	 */
	public abstract boolean sendPush(String aliasId, String alert, String msgTitle, String msgContent,
			Map<String, String> map, RoleType roleType);

	/**
	 * 
	 * 推送 只包含（通知、自定义参数）
	 * 
	 * @Title: sendPush 
	 * @param aliasId 推送别名
	 * @param alert  通知
	 * @param map 自定义参数
	 * @return  boolean true 成功 false 失败
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	public abstract boolean sendPush(String aliasId, String alert, Map<String, String> map, RoleType roleType);

	/**
	 * 
	 * 推送消息，不包含(自定义标题)
	 * 
	 * @Description:封装iOS消息推送参数 
	 * @param aliasId 设备别名 
	 * @param alert 通知 
	 * @param msgContent 自定义消息内容 
	 * @author cheshaowei
	 *  
	 */
	public abstract boolean sendPush(String aliasId, String alert, String msgContent, RoleType roleType);

	/**
	 * 
	 * 推送消息，只包含(通知、自定义内容)
	 * @param aliasId 设备别名 
	 * @param msgContent 消息内容 
	 * @author cheshaowei 
	 * 
	 */
	public abstract boolean sendPush(String aliasId, String msgContent, RoleType roleType);

	public static JPushClient getIosJPushClient() {
		return iosJPushClient;
	}

	public static void setIosJPushClient(JPushClient iosJPushClient) {
		AbstractSendPush.iosJPushClient = iosJPushClient;
	}

	public static JPushClient getAndroidJPushClient() {
		return androidJPushClient;
	}

	public static void setAndroidJPushClient(JPushClient androidJPushClient) {
		AbstractSendPush.androidJPushClient = androidJPushClient;
	}

}
